"""
    Set数据类型API
"""
import redis

pool = redis.ConnectionPool(host="192.168.100.3" , port=6379 , decode_responses=True)

client = redis.Redis(connection_pool=pool)

client.flushdb()

# 插入：
client.sadd("set1" , "s1" , "s2" , "s3")
# 查询：
print(client.smembers("set1"))

# 查看指定元素：
print(client.sismember("set1" , "s3"))

# 查看元素的个数：
print(client.scard("set1"))

# 删除：
# client.srem("set1" , "s2" , "s3")
# print(client.smembers("set1"))

# 随机查询，不会删除元素
# print(client.srandmember("set1" , 2))
# # 随机查询，删除元素：
# print(client.spop("set1"))
# print(client.smembers("set1"))

# 迁移：
client.sadd("s1" , "v1" , "v2" , "v3")
client.sadd("s2" , "v3" , "v4" , "v5")
# client.smove("s2" , "s1" , "v5")
print(client.smembers("s1"))
print(client.smembers("s2"))

# 交集：
print(client.sinter("s1" , "s2")) # v3
# 并集：
print(client.sunion("s1" , "s2")) # v1 -- v5
# 差集：
print(client.sdiff("s1" , "s2")) # v1 v2



